package com.cloud.client.controller;

import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cloud.client.ServiceInstance;
import org.springframework.cloud.client.discovery.DiscoveryClient;
import org.springframework.cloud.netflix.eureka.EurekaDiscoveryClient;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @author: zoub
 * @date 2020/11/12 11:34
 **/
@Slf4j
@RestController
public class EurekaController {

    @Autowired
    private DiscoveryClient discoveryClient;
    @Autowired
    private EurekaDiscoveryClient eurekaDiscoveryClient;

    /**
     * 获取所有注册的服务
     */
    @GetMapping("servers")
    public List<String> servers() {
        return discoveryClient.getServices();
    }

    /**
     * 根据ServerId查询服务所有实例
     */
    @GetMapping("server")
    public List<ServiceInstance> server() {
        //这里是application name 坑坑坑
        return discoveryClient.getInstances("service-producer");
    }


    /**
     * 获取所有注册的服务
     */
    @GetMapping("ekaServers")
    public List<String> ekaServers() {
        return eurekaDiscoveryClient.getServices();
    }

    /**
     * 根据ServerId查询服务所有实例
     */
    @GetMapping("ekaServer")
    public List<ServiceInstance> ekaServer() {
        //这里是application name 坑坑坑
        return eurekaDiscoveryClient.getInstances("service-producer");
    }



}
